package service;

import java.util.ArrayList;
import java.util.List;

import dao.Address;
import dao.User;
import dao.AddressDAO;

import org.apache.log4j.Logger;

import util.encryption;
import util.sendMail;

import java.security.MessageDigest;

public class AddressService {
	//这里声明了，但是我不需要new了，应为spring为我们管理了new的过程
	private AddressDAO addressDAO;
	public static Logger log = Logger.getLogger(AddressService.class);
	
	//定义随即字符串的长度
	private int rndLength = 20 ;
	
	public List provinceAddress(String province) {
		List<Address>  a = addressDAO.findProvinceAddress(province);
		List<String> list = new ArrayList();
		for(int i=0;i<a.size();i++)  
		{
			Address addr =a.get(i);
			list.add(addr.getLevel2cn());
		}
		System.out.println("level2cnAddress");
		return list;
		
	}
	
	public List cityAddress(String city) {
		List<Address>  a = addressDAO.findCityAddress(city);
		List<String> list = new ArrayList();
		for(int i=0;i<a.size();i++)  
		{
			Address addr =a.get(i);
			list.add(addr.getLevel3cn());
		}
		System.out.println("level3cnAddress");
		return list;
		
	}
	public List areaAddress(String area) {
		List<Address>  a = addressDAO.findAreaAddress(area);
		List<String> list = new ArrayList();
		for(int i=0;i<a.size();i++)  
		{
			Address addr =a.get(i);
			list.add(addr.getLevel4cn());
		}
		System.out.println("level4cnAddress");
		return list;
		
	}
	
	public List streetAddress(String street) {
		List<Address>  a = addressDAO.findStreetAddress(street);
		List<String> list = new ArrayList();
		for(int i=0;i<a.size();i++)  
		{
			Address addr =a.get(i);
			list.add(addr.getLevel5cn());
		}
		System.out.println("level5cnAddress");
		return list;
		
	}
	
	//业务逻辑层
	public List initAddress() {
		List<Address>  a =  addressDAO.findByAddrlevel(1);
		List<String> list =new  ArrayList();
		System.out.println(a.size());
		for(int i=0;i<a.size();i++)  
		{
			Address addr =a.get(i);
			list.add(addr.getLevel1cn());
		}
		System.out.println("initAddress");
		return list;
	}
	
	//huyu
	public int findIdByStr(String str) {
		List temp=addressDAO.findByFullcninfo(str);
		if(temp==null || temp.size()==0) return 0;
		Address address=(Address)temp.get(0);
		if(address!=null)	return address.getAddressid();
		return 0;
	}
	public static Logger getLog() {
		return log;
	}
	public static void setLog(Logger log) {
		AddressService.log = log;
	}
	public int getRndLength() {
		return rndLength;
	}
	public void setRndLength(int rndLength) {
		this.rndLength = rndLength;
	}
	public AddressDAO getAddressDAO() {
		return addressDAO;
	}
	public void setAddressDAO(AddressDAO addressDAO) {
		this.addressDAO = addressDAO;
	}
}